package com.gylang.print.pdf.domain.component.img;

import com.gylang.easy.lazy.FunBuilder;
import com.gylang.print.pdf.domain.PdfPageWrapper;
import com.gylang.print.pdf.domain.component.BasePdfComponent;
import com.gylang.print.pdf.enums.PdfComponentEnums;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import java.io.File;
import java.io.InputStream;

/**
 * @author gylang
 * data 2021/6/4
 */
@EqualsAndHashCode(callSuper = true)
@Setter
@Getter
public class ImgComponent extends BasePdfComponent implements FunBuilder<ImgComponent> {

	/** 图片地址 */
	private String imgUrl;
	/** 图片文件 */
	private File file;
	/** 文件流 */
	private InputStream inputStream;
	/** byte */
	private byte[] bytes;
	/** 图片来源 */
	private ImgSource imgSource;


	/** 格式 */
	private String suffix = "png";
	// 位置 -------------------------------------------------------------------------------


	/** 方向 0水平 1垂直 */
	private int direct;


	public ImgComponent() {
		super(PdfComponentEnums.IMG.getType());
	}

	public ImgComponent(PdfPageWrapper pageWrapper) {
		super(PdfComponentEnums.IMG.getType());
		this.pageWrapper = pageWrapper;
	}


	public void setImgUrl(String imgUrl) {
		this.imgUrl = imgUrl;
		imgSource = ImgSource.URL;
	}

	public void setFile(File file) {
		this.file = file;
		imgSource = ImgSource.FILE;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
		imgSource = ImgSource.INPUT_STREAM;
	}

	public void setBytes(byte[] bytes) {
		this.bytes = bytes;
		imgSource = ImgSource.BYTE_ARRAY;
	}



	public enum ImgSource {
		/** url */
		URL,

		/** file对象 */
		FILE,

		/** 输入流 */
		INPUT_STREAM,

		/** byte数组 */
		BYTE_ARRAY
	}
}
